from time import sleep
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.baidu.com/')
sleep(3)
driver.find_element_by_partial_link_text('新闻').click()
sleep(3)
has = driver.window_handles
driver.switch_to.window(has[1])
sleep(3)
driver.find_element_by_partial_link_text('军事').click()
sleep(2)
driver.find_element_by_partial_link_text('中国海军首支潜艇部队，生日快乐').click()
sleep(3)
had = driver.window_handles
driver.switch_to.window(had[2])
driver.close()
driver.switch_to.window(had[1])
driver.close()
driver.switch_to.window(has[0])
sleep(2)
driver.find_element_by_id('kw').send_keys('Selenium')
sleep(2)
driver.find_element_by_id('su').click()
sleep(3)
driver.quit()
